package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    void addOrder(Orders order);

    @Insert("insert into order_detail ( name, image, order_id, dish_id, setmeal_id, dish_flavor, number, amount) " +
            "values (#{name}, #{image}, #{orderId}, #{dishId}, " +
            "#{setmealId}, #{dishFlavor}, #{number}, #{amount})")
    void addOrderDetail(OrderDetail orderDetail);

    Page<Orders> getHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from order_detail where order_id=#{id}")
    List<OrderDetail> getOrderDetails(Long id);

    @Select("select * from orders where id=#{id}")
    Orders getOrder(Long id);

    void updateOrder(Orders orders);

    @Select("select count(*) from orders where status=#{status}")
    Integer getStatusCount(Integer status);

    @Select("select * from orders where status=#{status} and order_time <#{now} ")
    List<Orders> executeTimeOut( Integer status, LocalDateTime now);

}
